//
//  BaseLogInViewController.m
//  gitHub自定义登录按钮及推送动画
//
//  Created by rimi on 16/10/17.
//  Copyright © 2016年 rimi. All rights reserved.
//

#import "BaseLogInViewController.h"
#import "DDLogInTransitions.h"
#import "DDLoglnButton.h"

@interface BaseLogInViewController ()<UIViewControllerTransitioningDelegate>
@property (nonatomic,strong)DDLoglnButton* loginBtn;

@end

@implementation BaseLogInViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createPresentControllerButton:CGRectMake(40, CGRectGetHeight(self.view.bounds) - (40 + 80), [UIScreen mainScreen].bounds.size.width - 80, 40) btnBgColor:[UIColor blackColor] btnAlpha:1];
    
 }
#pragma mark 创建动画按钮的方法
- (void)createPresentControllerButton:(CGRect)frame btnBgColor:(UIColor*)btnBgColor btnAlpha:(CGFloat)btnAlpha{
    self.loginBtn = [[DDLoglnButton alloc]initWithFrame:frame];
    [self.loginBtn setBackgroundImage:[UIImage imageNamed:@"dynamic"] forState:(UIControlStateNormal)];
    [self.loginBtn setBackgroundColor:btnBgColor];
     self.loginBtn.alpha = btnAlpha;
    [self.loginBtn setTitle:@"登录" forState:(UIControlStateNormal)];
    [self.loginBtn addTarget:self action:@selector(PresentViewController:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.loginBtn];
    
}
- (void)PresentViewController:(DDLoglnButton *)button {
    
    typeof(self) __weak weak = self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       
            //网络正常 或者是密码账号正确跳转动画
          [button succeedAnimationWithSucessType:loginSucessWithPresentType Completion:^{
              [weak didPresentControllerButtonTouch:[UIViewController new]];
          }];
        //            //网络错误 或者是密码不正确还原动画
       //  [button failedAnimationWithPromptStr:@"登录错误" Completion:^{
         //    [weak didPresentControllerButtonTouch:[UIViewController new]];
 
          //}];
    });


}

- (void)didPresentControllerButtonTouch:(UIViewController*)skipViewController{
   
    skipViewController.transitioningDelegate = self;
    skipViewController.view.backgroundColor = [UIColor whiteColor];
//    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:skipViewController];
//    navigationController.transitioningDelegate = self;

    [self presentViewController:skipViewController animated:YES completion:nil];
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting
                                                                      sourceController:(UIViewController *)source {
    return [[DDLogInTransitions alloc]initWithTransitionDuration:0.4f StartingAlpha:0.5f isPush:true];
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    return [[DDLogInTransitions alloc]initWithTransitionDuration:0.4f StartingAlpha:0.8f isPush:false];
}


@end
